home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / disk / mt220.zip / SOURCE.ZIP / MTMEM.ASM < prev   
Assembly Source File  |  1997-03-27  |  7KB  |  269 lines

  1. comment ^
  2.  
  3.   MTMem - Memory to store mtdirs and mtprev[] for Move To (mt.com)
  4.   Copyright Jason Hood 1996-7.
  5.   Started:   5 May, 1996.
  6.   Finished:  2 June.
  7.   Modified: 29 October - updated to reflect changes in mt.cpp
  8.         10-11 February, 1997 - changed to AMIS, support for virtual machines
  9.          8 March - removed TOPMEM from INSTALL_TSR.
  10.         27 March - allow more than two previous directories by using a null-
  11.                separated list instead of fixed-length.
  12.  
  13.  
  14.   Usage: mtmem [d:/path] [;path[;path;path...]]
  15.   Where: d:/path    is the path to place the directory structure file.
  16.               Default is the same path as mtmem.com.
  17.      ;path...   is an initial list of previous directories. The first path
  18.               is the previous directory, second path is the before prev.
  19.               dir., etc., for a maximum of MaxPath*2 (132) characters.
  20.               Default is an empty string ("" is an invalid path.).
  21.  
  22.   Assumptions: all parameters are valid. Previous list is assumed to be smaller
  23.            than MaxPath*2 (since command line length is 127 characters,
  24.            shouldn't be a problem).
  25.  
  26.   Acknowledgements: Ralf Brown's interrupt list and AMIS;
  27.             DOSCLIP by Douglas Boling for instance data setup.
  28.  
  29.   You are free to use this code, or a portion thereof, as long as an appropriate
  30.   acknowledgement is made.
  31.  
  32.   Questions, suggestions and comments to hoodj@topaz.cqu.edu.au.
  33.  
  34. ^
  35.  
  36. VERSION_NUM    equ    210h
  37.  
  38. MaxPath     equ    80        ; These values are from dir.h
  39. MaxDir        equ    66
  40.  
  41. byt        equ    <byte ptr>
  42. wrd        equ    <word ptr>
  43. ofs        equ    <offset>
  44. jmps        equ    <jmp short>
  45.  
  46.  
  47. __TINY__    equ    0        ; Define tiny model for AMIS
  48.  
  49.         INCLUDE AMIS.MAC
  50.  
  51.         @Startup 3,00
  52.  
  53.  
  54. TSRcode@
  55.  
  56. StartupInfo     =       $
  57.  sisVersion    dw    3        ; Switcher structure ID
  58.  sisNextDev    dd    0        ; Ptr to prev startup structure
  59.  sisVirtDevFile dd    0        ; Ptr to name of opt dev drvr
  60.  sisReferenceData dd    0        ; Data for Win dev drivr
  61.  sisInstData    dd    0        ; Ptr to instance mem list
  62.  
  63. DataBlockPtr    dd    0        ; Ptr to instance data
  64. DataBlockSize    dw    0        ; Size of instance data
  65.         dd    0        ; Ptr to next block = 0 to
  66.         dw    0        ;   terminate list
  67.  
  68. ; Instance data
  69. DataBlock    =    $
  70.  
  71. mtdirs        db    MaxPath       dup (0)
  72. prev        db    2*MaxDir + 1  dup (0)
  73.  
  74. DataBlockEnd    =    $
  75.  
  76. INSTDATASIZE    equ    ofs DataBlockEnd - ofs DataBlock
  77.  
  78.  
  79. ; Multiplex service function - return the address for mt.com:
  80. ;   DX:AX            mtdirs
  81. ;   DX:AX+MaxPath        null-separated list of previous directories,
  82. ;                terminated by a null:
  83. ;
  84. ;   "c:\previous",0,"c:\before\previous",0,"c:\another\previous",0,0
  85.  
  86. address:
  87.     mov    dx, cs
  88.     mov    ax, ofs mtdirs
  89.     iret
  90.  
  91.  
  92.     HOOKED_INTS 2fh
  93.  
  94.     ALTMPX    'Adoxa', 'MTMem', VERSION_NUM,, address
  95.  
  96.  
  97. ; Initialise instance data
  98.     ISP_HEADER 2fh
  99.  
  100.     cmp    ax, 1605h        ; Windows launch
  101.     je    instance
  102.     cmp    ax, 4b05h        ; Switcher instance data
  103.     je    instance
  104.     jmp    ORIG_INT2Fh
  105. instance:
  106.     pushf
  107.     call    ORIG_INT2Fh
  108.     mov    wrd sisNextDev, bx
  109.     mov    wrd sisNextDev+2, es
  110.     push    cs            ; ES:BX point to switcher struc
  111.     pop    es
  112.     mov    bx, ofs StartupInfo
  113.  
  114.     iret
  115.  
  116. TSRcodeEnd@
  117.  
  118. ;-----------------------------------------------------------------------
  119.  
  120. _TEXT    SEGMENT 'CODE'
  121.     ASSUME    cs:_TEXT, ds:_INIT, es:TGROUP, ss:NOTHING
  122.  
  123. F_PATH    equ    01b
  124. F_INST    equ    10b
  125.  
  126. flags    db    0            ; Bit 0 - path was initialised
  127.                     ;     1 - already installed
  128. mtfile    db    'MTDIRS.DAT'            ; Filename to append to mtdirs
  129.  
  130.     @Startup2 PSP
  131.  
  132.     IF_INSTALLED get_segment
  133.     jmps    parse
  134.  
  135. get_segment:
  136.     mov    al, 10h
  137.     int    2dh
  138.     mov    es, dx
  139.     or    flags, F_INST
  140.  
  141. parse:    mov    si, 81h         ; Command line
  142.     xor    ah, ah            ; Terminating null
  143.  
  144. param:    lodsb
  145.     cmp    al, 0dh
  146.     je      done
  147.     cmp     al, ' '                 ; Ignore spaces
  148.     je      param
  149.     cmp    al, 9            ;  and tabs
  150.     je    param
  151.  
  152.     cmp    al, ';'                 ; The list of previous directories?
  153.     je    isprev
  154.     mov    di, ofs mtdirs        ; Offset for directory structure path
  155.     or    flags, F_PATH        ; Indicate a path was specified
  156.     jmps    copy
  157.  
  158. isprev: lodsb
  159.     mov    di, ofs prev
  160.  
  161. copy:   cmp     al, ' '                 ; End of this parameter
  162.     je    null
  163.     cmp    al, 9
  164.     je    null
  165.     cmp     al, 0dh
  166.     je    null
  167.     cmp    al, ';'                 ; Previous directory separator
  168.     jne    slash
  169.     mov    al, ah            ; Use a null instead
  170.     jmps    store
  171. slash:    cmp    al, '/'                 ; Replace slashes with backslashes
  172.     jne    nslash            ;  for comparison purposes
  173.     mov     al, '\'
  174.     jmps    store
  175. nslash: cmp     al, 'a'                 ; Convert lower to uppercase for the
  176.     jb    store            ;  same reason and to select the drive
  177.     cmp     al, 'z'
  178.     ja      store
  179.     and     al, 5fh
  180. store:  stosb
  181.     lodsb
  182.     jmps    copy
  183.  
  184. null:    mov    byt es:[di], ah     ; Place the terminating null
  185.     cmp    di, ofs prev        ; If copying the path
  186.     jae    null2            ;  point BX to its end
  187.     mov    bx, di
  188.     jmps    more
  189. null2:    inc    di            ; The null to terminate the list
  190.     mov    byt es:[di], ah
  191. more:    cmp    al, 0dh         ; More parameters?
  192.     jne    param
  193.  
  194. done:    test    flags, F_PATH        ; Was a path entered?
  195.     jnz     append                  ; Yes, so don't search for one
  196.  
  197.     mov    bx, es            ; Save where I'm copying in BX
  198.     mov    ax, ds:[2ch]        ; Get the environment segment
  199.     mov    dx, ax            ;  and save it in DX
  200.     mov    es, ax
  201.     ASSUME    es:NOTHING
  202.     sub    di, di
  203.     xor     al, al
  204.     mov     cx, 0ffffh
  205. envend: repne   scasb                   ; End of environment variable
  206.     cmp    byt es:[di], al     ; End of environment?
  207.     jne     envend
  208.     inc     di                      ; Point past the word stored after
  209.     inc    di            ;  the environment variables to get
  210.     inc    di            ;  the path of mtmem.com
  211.     mov    si, ofs mtdirs        ; Swap source and destination
  212.     xchg    si, di            ;  for the copy
  213.     mov     ds, dx
  214.     mov    es, bx
  215.     ASSUME    ds:NOTHING, es:TGROUP
  216. mvpath: lodsb
  217.     or      al, al                  ; Terminating null?
  218.     jz    append
  219.     stosb
  220.     cmp     al, '\'
  221.     jne     mvpath
  222.     mov     bx, di                  ; BX will point to "MTMEM.COM"
  223.     jmps    mvpath
  224.  
  225. append: mov    di, bx            ; The end of the path
  226.     cmp     byt es:[di-1], '/'      ; Is there a trailing slash
  227.     je      app
  228.     cmp    byt es:[di-1], '\'      ;  or backslash?
  229.     je      app
  230.     mov    byt es:[di], '\'        ; No, so add one
  231.     inc     di
  232. app:    push    cs
  233.     pop    ds
  234.     ASSUME    ds:_TEXT
  235.     mov    si, ofs mtfile        ; The filename to append
  236.     movsw                           ; It's ten characters
  237.     movsw                ;  which means five words
  238.     movsw
  239.     movsw
  240.     movsw
  241.     mov    byt es:[di], al     ; Terminating null (AL zero from above)
  242.  
  243.     test    flags, F_INST
  244.     jz    install
  245.     mov    ah, 4ch         ; AL still zero
  246.     int    21h
  247.  
  248. install:
  249.     INSTALL_TSR , BEST, , installed
  250.  
  251. installed:
  252.     ; Initialise the switcher instance structure
  253.     mov    ds, ax
  254.     ASSUME    ds:TGROUP
  255.  
  256.     mov    wrd DataBlockPtr+2, ax
  257.     mov    wrd DataBlockPtr, ofs DataBlock
  258.     mov    wrd DataBlockSize, INSTDATASIZE
  259.  
  260.     mov    wrd sisInstData+2, ax
  261.     mov    ax, ofs DataBlockPtr
  262.     mov    wrd sisInstData, ax
  263.  
  264.     ret
  265.  
  266. _TEXT    ENDS
  267.  
  268.     end    INIT
  269.